package com.wxzz.elearing.evaluation.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.evaluation.dto.*;
import com.wxzz.elearing.evaluation.entity.BusinessCategory;
import com.wxzz.elearing.evaluation.entity.BusinessCategoryReport;
import com.wxzz.elearing.evaluation.entity.EvaluationCriterion;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryRuleService;
import com.wxzz.elearing.evaluation.service.IBusinessCategoryService;
import com.wxzz.elearing.evaluation.vo.GeneralStatisticsVo;
import com.wxzz.elearing.evaluation.vo.StarStatisticsVo;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 行业类目/组别管理 前端控制器
 * </p>
 *
 * @author
 * @since 2021-04-10
 */
@RestController
@RequestMapping("/business-category")
@Api(tags = "行业类目/组别管理接口(总后台)")
public class BusinessCategoryController {

    @Autowired
    private IBusinessCategoryService businessCategoryService;


    @ApiOperation(value = " 添加或修改类目(总后台)", notes = " 添加或修改类目(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "saveBusinessCategory", method = RequestMethod.POST)
    public ReturnVO saveBusinessCategory(@RequestBody BusinessCategory businessCategory) {
        return businessCategoryService.saveBusinessCategory(businessCategory);
    }

    @ApiOperation(value = " 类目列表(总后台)", notes = " 类目列表(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listBusinessCategory", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategory>>> listBusinessCategory(@RequestBody BusinessCategoryDto businessCategoryDto) {
        return businessCategoryService.listBusinessCategory(businessCategoryDto);
    }

    @ApiOperation(value = " 列出测评标准的类目列表(总后台)", notes = " 列出测评标准的类目列表(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listBusinessCategory4EvaluationCriterion", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategory>>> listBusinessCategory4EvaluationCriterion(@Valid @RequestBody BusinessCategory4EvaluationCriterionDto businessCategory4EvaluationCriterionDto) {
        return businessCategoryService.listBusinessCategory4EvaluationCriterion(businessCategory4EvaluationCriterionDto);
    }

    @ApiOperation(value = " 根据行业类目id删除(总后台)", notes = " 根据行业类目id删除(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "deleteByBusinessCategoryId/{BusinessCategoryId}", method = RequestMethod.POST)
    public ReturnVO deleteByBusinessCategoryId(@PathVariable Long BusinessCategoryId) {
        return businessCategoryService.deleteByBusinessCategoryId(BusinessCategoryId);
    }

    @ApiOperation(value = " 列出报告设置(总后台)", notes = " 列出报告设置(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listBusinessCategoryReport", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<BusinessCategoryReport>>> listBusinessCategoryReport(@Valid @RequestBody BusinessCategoryRuleReportDto businessCategoryRuleReportDto) {
        return businessCategoryService.listBusinessCategoryReport(businessCategoryRuleReportDto);
    }

    @ApiOperation(value = " 添加或修改测评报告设置(总后台)", notes = " 添加或修改测评报告设置(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "saveBusinessCategoryReport", method = RequestMethod.POST)
    public ReturnVO saveBusinessCategoryReport(@RequestBody BusinessCategoryReport businessCategoryRuleReport) {
        return businessCategoryService.saveBusinessCategoryReport(businessCategoryRuleReport);
    }

    @ApiOperation(value = " 新增或修改测评标准(总后台)", notes = " 新增或修改测评标准(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "saveEvaluationCriterion", method = RequestMethod.POST)
    public ReturnVO saveEvaluationCriterion(@Valid @RequestBody EvaluationCriterion evaluationCriterion) {
        return businessCategoryService.saveEvaluationCriterion(evaluationCriterion);
    }

    @ApiOperation(value = " 列出测评标准(总后台)", notes = " 列出测评标准(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "listEvaluationCriterion", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<EvaluationCriterion>>> listEvaluationCriterion(@Valid @RequestBody EvaluationCriterionDto evaluationCriterionDto) {
        return businessCategoryService.listEvaluationCriterion(evaluationCriterionDto);
    }



    @ApiOperation(value = " 根据测评标准id删除(总后台)", notes = " 根据测评标准id删除(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "deleteEvaluationCriterion/{evaluationCriterionId}", method = RequestMethod.POST)
    public ReturnVO deleteEvaluationCriterion(@PathVariable Long evaluationCriterionId) {
        return businessCategoryService.deleteEvaluationCriterion(evaluationCriterionId);
    }


    @ApiOperation(value = " 综合数据(概况总览)(总后台)", notes = " 综合数据(概况总览)(总后台)", httpMethod = "POST", tags = "总后台")
    @RequestMapping(value = "selectGeneralStatisticsVo", method = RequestMethod.POST)
    public ReturnVO<GeneralStatisticsVo> selectGeneralStatisticsVo() {
        return businessCategoryService.selectGeneralStatisticsVo();
    }


    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = " 当前企业星级认证(概况总览)(后台)", notes = " 综合数据(概况总览)(后台)", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "selectStarStatisticsVo", method = RequestMethod.POST)
    public ReturnVO<StarStatisticsVo> selectStarStatisticsVo(@RequestHeader String token) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return businessCategoryService.selectStarStatisticsVo(jsonObject.getLong("enterpriseId"));
    }

}
